<template>
  <div class="comp-research-wrapper window-wrapper">
    <div class="container">
      <div class="copyright-wrapper">
        <h3 v-if="$store.state.language === 'zh-CN'">
          <i class="el-icon-star-off" /> 专利著作
          <span class="read-more" @click="$router.push('/Patent')">更多</span>
        </h3>
        <h3 v-else>
          <i class="el-icon-star-off" /> Patent work
          <span class="read-more" @click="$router.push('/Patent')">More</span>
        </h3>
        <div class="copyright-container" v-if="$store.state.language === 'zh-CN'">
          <div class="copyright-instance" v-for="(item, _) in copyRightList" :key="_">
            <div class="content">{{item.content}}</div>
          </div>
        </div>
        <div class="copyright-container" v-else>
          <div class="copyright-instance" v-for="(item, _) in enCopyRightList" :key="_">
            <div class="content">{{item.content}}</div>
          </div>
        </div>
      </div>

      <div class="project-wrapper">
        <h3 v-if="$store.state.language === 'zh-CN'">
          <i class="el-icon-suitcase" /> 科研项目
          <span class="read-more" @click="$router.push('/Project')">更多</span>
        </h3>
        <h3 v-else>
          <i class="el-icon-suitcase" /> Research Projects
          <span class="read-more" @click="$router.push('/Project')">More</span>
        </h3>
        <div class="project-container" v-if="$store.state.language === 'zh-CN'">
          <div class="project-instance" v-for="(item, _) in projectList" :key="_">
            <div class="content" v-html="item.content"></div>
          </div>
        </div>
        <div class="project-container" v-else>
          <div class="project-instance" v-for="(item, _) in enProjectList" :key="_">
            <div class="content">{{item.content}}</div>
          </div>
        </div>
        <!-- <div class="project-container ql-editor" v-if="$store.state.language === 'zh-CN'">
          <div v-html="content">
            {{content}}
          </div>
        </div>
        <div class="project-container ql-editor" v-else>
          <div v-html="enContent">
            {{enContent}}
          </div>
        </div>-->
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { RequestStatus } from "../utils/constans";
import { formatBackTime } from "../utils/common";
import { Notification } from "element-ui";
import { iResearchProject, iCopyRight } from "../typings/research";
import $api from "../api";
import mockProject from "../mock/project";
import mockCopy from "../mock/paten";

@Component
export default class CompResearch extends Vue {
  private projectList: iResearchProject[] = [];
  private enProjectList: iResearchProject[] = [];
  private copyRightList: iCopyRight[] = [];
  private enCopyRightList: iCopyRight[] = [];
  private content: string = "";
  private enContent: string = "";

  mounted() {
    this.getProjectList();
    this.getCopyRightList();
  }

  getProjectList() {
    const succ = (res: any) => {
      (res as any).map((record: iResearchProject) => {
        if (record.language === "英语" && this.enProjectList.length < 5) {
          this.enProjectList.push(record);
        } else if (record.language !== "英语" && this.projectList.length < 5) {
          this.projectList.push(record);
        }
      });
    };
    if (this.$store.state.offModel) {
      succ(mockProject);
    } else {
      $api.research.findAllresearchProjectClient().then(succ);
    }
  }

  getCopyRightList() {
    const succ = (res: any) => {
      (res as any).map((record: iCopyRight) => {
        if (record.language === "英语" && this.enCopyRightList.length < 5) {
          this.enCopyRightList.push(record);
        } else if (
          record.language !== "英语" &&
          this.copyRightList.length < 5
        ) {
          this.copyRightList.push(record);
        }
      });
    };
    if (this.$store.state.offModel) {
      succ(mockCopy);
    } else {
      $api.research.findAllPatentsCopyrightClient().then(succ);
    }
  }
}
</script>

<style lang="scss" scoped>
.comp-research-wrapper {
  padding: 0 30px;
  margin-top: 15px;
  .container {
    width: 1200px;
    margin: auto;
  }
  .project-wrapper,
  .copyright-wrapper {
    h3 {
      text-align: left;
      color: white;
      margin: 0;
      padding: 10px 20px;
      background: #113f6c;
      .read-more {
        float: right;
        cursor: pointer;
        &:hover {
          color: #f5ae54;
        }
      }
    }
  }
  .project-wrapper {
    h3 {
      background: #f5ae54;
      .read-more:hover {
        color: #113f6c;
      }
    }
    margin-top: 15px;
  }
  .project-container {
    display: flex;
    flex-wrap: wrap;
    background: white;
  }
  .project-instance {
    width: 100%;
    padding: 5px 20px;
    box-sizing: border-box;
    background: white;
    text-align: left;
    border-right: 1px solid #ededed;
    position: relative;
    border-bottom: 1px solid #ededed;
    &:hover {
      z-index: 1;
      cursor: pointer;
      box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.1);
    }
    .time {
      display: inline-block;
      padding: 5px 10px;
      font-size: 14px;
      border-radius: 5px;
      color: gray;
      border: 1px solid gray;
    }
    .content {
      margin: 15px 0;
      text-overflow: ellipsis;
    }
    .role {
      position: absolute;
      bottom: 10px;
      right: 10px;
      color: #f5ae54;
    }
  }
  .copyright-instance {
    text-align: left;
    background: white;
    padding: 10px;
    // color: white;
    margin-bottom: 1px;
    // border-bottom: 1px solid #113f6c;
  }
}
// @media screen and (max-width: 700px) {
//   .comp-research-wrapper {
//     padding: 30px 10px;
//     .project-instance {
//       width: 50%;
//     }
//   }
// }
</style>